from confluent_kafka.admin import AdminClient, ClusterMetadata
from confluent_kafka.cimpl import NewTopic, Message, TopicPartition, Producer
from confluent_kafka import Consumer
# admin = AdminClient({"bootstrap.servers": "10.0.0.252:9092"})


# def list_topics():
#     # list all topics
#     t = admin.list_topics()
#     assert isinstance(t, ClusterMetadata)
#     for topic in t.topics.keys():
#         print(topic)


# create topic
# future = admin.create_topics([NewTopic("second_topic", 2, 2)])
# t = future['second_topic']
# t.result()
#
# # delete topic
# admin.delete_topics(["second_topic"])['second_topic'].result()
#
# list_topics()

# consumer = Consumer({"bootstrap.servers": "10.0.0.252:9092", "group.id": 0})
# consumer.subscribe(["news", "sport"])
# print(consumer.list_topics("news"))
# consumer.seek(TopicPartition('news', 0, 2))
# consumer.assign([TopicPartition('news', 0, 5), TopicPartition('sport', 0, 3)])
# print("Polling ......")
# while True:
#     msg = consumer.poll()
#     print(msg.value())
import logging
from logging import FileHandler

producer = Producer({"bootstrap.servers": "10.0.0.252:9092"})
while True:
    line = input("Enter message: ")
    producer.produce("topic2", line, partition=0)




